﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<brjostagjof.Models.New>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Lesa frétt
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
     <a href="/Home/Frettir" class="linksWhite">Til baka í fréttir</a>
    <h2 class="title"><%: Model.ArticleBase.InformationBase.headline %></h2>
    <p class="meta">Höfundur: <a href="../../MySite/ViewUserByID/<%:Model.ArticleBase.User.ID  %>"><%: Model.ArticleBase.User.name%></a>, <%: Model.ArticleBase.InformationBase.date %>
	    &nbsp;&bull;&nbsp;
        <a href="/Home/GetNewsByCategoryID/<%: Model.ArticleBase.ArticleCategory.ID %>" class="permalink"> <%: Model.ArticleBase.ArticleCategory.name %></a>
        <span id="baetaSafn<%:Model.articleBaseID %>">&nbsp;&bull;&nbsp;<a href="#"  onclick="saveGrein(<%: Model.articleBaseID %>);">Bæta í safn</a></span>
        </p>
        <span id="<%:Model.articleBaseID %>"></span>
    <div class="entry">
    <div class="entry-bgtop">
    <div class="entry-bgbtm">
        <%= Model.ArticleBase.InformationBase.context %>
    </div>
    </div>
    </div>


    <!-- Fyrir comment hlutann, sem sýnir öll comment með sama ArticleBase
    ID. -->

    <% if(Page.User.IsInRole("Administrators"))
       { %>
    <p><a href="/Home/EditNews/<%: Model.articleBaseID %>">Breyta frétt</a></p>
    <% } %>
    <input type="hidden" id="ID" value="<%: Model.articleBaseID %>" />
    <fieldset id="commentField">
        <ul id="commentList" class="commentList">
        </ul>
        <% if (Page.User.Identity.IsAuthenticated)
           { %>
        <ul class="commentList" id="commentWindow">
            <li class="commentAdd">
			    <textarea id="CommentText" name="CommentText" rows="3" cols="20"></textarea>
			    <label>
				    <input id="submitButton" type="submit" value="Skrifa athugasemd" />
			    </label>
		    </li>
	    </ul>
        <% } %>
    </fieldset>
    <script type="text/html" id="commentTemplate">
    <li class="allComments">
        <div class="commentBody">
            <a href="../../MySite/ViewUserByID/${userID}">${userName}</a>
            &nbsp;|&nbsp;${commentDate}<br/>
            <span>${message}</span>
        </div>
    </li>
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#submitButton").click(function () {
                var result = { "articleID": $("#ID").val(), "message": $("#CommentText").val() };
                $.post("/Home/AddComment/", result, function (n) {
                    $(".allComments").remove();
                    $("#commentTemplate").tmpl(n).appendTo("#commentList");
                    $("#CommentText").val("");
                });
            });

            GetComments();
        });

        function GetComments() {
            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                url: "/Home/GetComments/" + $("#ID").val(),
                data: {},
                dataType: "json",
                success: function (n) {
                    $("#commentTemplate").tmpl(n).appendTo("#commentList");
                },
                error: function (xhr, err) {
                    alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
                }
            });
        }
    </script>
</asp:Content>